Quản lý nhân sự công ty bằng c# _ full source code
60.487 lượt xem;
- frmDMTonGiao.cs
- QuanLyNhanSu /
- project /
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.SqlClient;
10 using Telerik.WinControls;
11 using Telerik.Data;
12 using QuanLyNhanSu.Class;
13
14 namespace QuanLyNhanSu
15 {
16 public partial class frmDMTonGiao : RadForm
17 {
18 clsdmtongiao c = new clsdmtongiao();
19 int k = 0;
20 public frmDMTonGiao()
21 {
22 InitializeComponent();
23 c.laydl("tbl_DMTonGiao");
24 txtmatg.DataBindings.Add("text", c.ds, "tbl_DMTonGiao.MaTG");
25 txttentg.DataBindings.Add("text", c.ds, "tbl_DMTonGiao.TenTG");
26 dgv_DMTG.DataSource = c.ds;
27 dgv_DMTG.DataMember = "tbl_DMTonGiao";
28
29 dgv_DMTG.Columns[0].HeaderText = "Mã tôn giáo";
30 dgv_DMTG.Columns[1].HeaderText = "Tên tôn giáo";
31 }
32 public void setbutton(bool b)
33 {
34 cmdCapnhat.Enabled = b;
35 cmdthem.Enabled = b;
36 cmdthoat.Enabled = b;
37 cmdxoa.Enabled = b;
38 cmdluu.Enabled = !b;
39 }
40
41 private void frmDMTonGiao_Load(object sender, EventArgs e)
42 {
43 setbutton(true);
44 }
45
46 private void cmdthoat_Click(object sender, EventArgs e)
47 {
48 Close();
49 }
50
51 private void txtmatg_KeyPress(object sender, KeyPressEventArgs e)
52 {
53 if (!Char.IsNumber(e.KeyChar))
54 {
55 RadMessageBox.Show("\nBạn phải nhập số !\n", "Thông báo",MessageBoxButtons.OK,RadMessageIcon.Error);
56 txtmatg.Text = "";
57 txtmatg.Focus();
58 }
59 }
60
61 private void cmdxoa_Click(object sender, EventArgs e)
62 {
63 if (dgv_DMTG.SelectedRows.Count == 0)
64 {
65 RadMessageBox.Show("\nBạn phải chọn dòng để xóa !\n", "Thông Báo", MessageBoxButtons.OK, RadMessageIcon.Error);
66 return;
67 }
68 else
69 {
70 DialogResult rs = RadMessageBox.Show("\nBạn thật sự muốn xóa thông tin này !?\n", "Thông Báo", MessageBoxButtons.YesNo, RadMessageIcon.Question);
71 if (rs == DialogResult.Yes)
72 {
73 c.xoa("tbl_DMTonGiao", int.Parse(txtmatg.Text.Trim()), "MaTG");
74 c.laydl("tbl_DMTonGiao");
75
76 }
77 }
78 }
79
80 private void cmdthem_Click(object sender, EventArgs e)
81 {
82 txtmatg.Text = "";
83 txttentg.Text = "";
84 txtmatg.ReadOnly = false;
85 txttentg.ReadOnly = false;
86 txtmatg.Focus();
87 setbutton(false);
88 k = 1;
89 }
90
91 private void cmdCapnhat_Click(object sender, EventArgs e)
92 {
93 if (dgv_DMTG.SelectedRows.Count == 0)
94 {
95 RadMessageBox.Show("\nBạn phải chọn dòng để cập nhật !\n", "Thông Báo", MessageBoxButtons.OK, RadMessageIcon.Error);
96 return;
97 }
98 else
99 {
100 txttentg.ReadOnly = false;
101 txttentg.Focus();
102 setbutton(false);
103 k = 2;
104 }
105 }
106
107 private void cmdluu_Click(object sender, EventArgs e)
108 {
109 DialogResult rs = RadMessageBox.Show("\nBạn thật sự muốn lưu thông tin này không ?\n", "Thông Báo", MessageBoxButtons.YesNo, RadMessageIcon.Question);
110 if (rs == DialogResult.Yes)
111 {
112 if (k == 1)
113 {
114 if (txtmatg.Text == "" || txttentg.Text == "")
115 {
116 RadMessageBox.Show(this, "\nBạn phải nhập đầy đủ thông tin vào !\n", "Thông báo", MessageBoxButtons.OK, RadMessageIcon.Error);
117 return;
118 }
119 else
120 { //thêm mẩu tin mới vào datagirdview
121 c.them("tbl_dmTonGiao", int.Parse(txtmatg.Text.Trim())
122 , txttentg.Text.Trim());
123 }
124 }
125 else if (k == 2)
126 {
127 if (txtmatg.Text == "" || txttentg.Text == "")
128 {
129 RadMessageBox.Show(this, "\nBạn phải nhập đầy đủ thông tin vào !\n", "Thông báo", MessageBoxButtons.OK, RadMessageIcon.Error);
130 return;
131 }
132 else
133 {
134 //cập nhật mẩu tin
135 c.sua("tbl_DMTonGiao", int.Parse(txtmatg.Text.Trim()),
136 txttentg.Text.Trim(), "MaTG", "tenTG");
137 }
138 }
139 }
140 //load lại dữ liệu
141 c.laydl("tbl_DMTonGiao");
142 txtmatg.ReadOnly = true;
143 txttentg.ReadOnly = true;
144 k = 0;
145 setbutton(true);
146 }
147 }
148 }
149
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.SqlClient;
10 using Telerik.WinControls;
11 using Telerik.Data;
12 using QuanLyNhanSu.Class;
13
14 namespace QuanLyNhanSu
15 {
16 public partial class frmDMTonGiao : RadForm
17 {
18 clsdmtongiao c = new clsdmtongiao();
19 int k = 0;
20 public frmDMTonGiao()
21 {
22 InitializeComponent();
23 c.laydl("tbl_DMTonGiao");
24 txtmatg.DataBindings.Add("text", c.ds, "tbl_DMTonGiao.MaTG");
25 txttentg.DataBindings.Add("text", c.ds, "tbl_DMTonGiao.TenTG");
26 dgv_DMTG.DataSource = c.ds;
27 dgv_DMTG.DataMember = "tbl_DMTonGiao";
28
29 dgv_DMTG.Columns[0].HeaderText = "Mã tôn giáo";
30 dgv_DMTG.Columns[1].HeaderText = "Tên tôn giáo";
31 }
32 public void setbutton(bool b)
33 {
34 cmdCapnhat.Enabled = b;
35 cmdthem.Enabled = b;
36 cmdthoat.Enabled = b;
37 cmdxoa.Enabled = b;
38 cmdluu.Enabled = !b;
39 }
40
41 private void frmDMTonGiao_Load(object sender, EventArgs e)
42 {
43 setbutton(true);
44 }
45
46 private void cmdthoat_Click(object sender, EventArgs e)
47 {
48 Close();
49 }
50
51 private void txtmatg_KeyPress(object sender, KeyPressEventArgs e)
52 {
53 if (!Char.IsNumber(e.KeyChar))
54 {
55 RadMessageBox.Show("\nBạn phải nhập số !\n", "Thông báo",MessageBoxButtons.OK,RadMessageIcon.Error);
56 txtmatg.Text = "";
57 txtmatg.Focus();
58 }
59 }
60
61 private void cmdxoa_Click(object sender, EventArgs e)
62 {
63 if (dgv_DMTG.SelectedRows.Count == 0)
64 {
65 RadMessageBox.Show("\nBạn phải chọn dòng để xóa !\n", "Thông Báo", MessageBoxButtons.OK, RadMessageIcon.Error);
66 return;
67 }
68 else
69 {
70 DialogResult rs = RadMessageBox.Show("\nBạn thật sự muốn xóa thông tin này !?\n", "Thông Báo", MessageBoxButtons.YesNo, RadMessageIcon.Question);
71 if (rs == DialogResult.Yes)
72 {
73 c.xoa("tbl_DMTonGiao", int.Parse(txtmatg.Text.Trim()), "MaTG");
74 c.laydl("tbl_DMTonGiao");
75
76 }
77 }
78 }
79
80 private void cmdthem_Click(object sender, EventArgs e)
81 {
82 txtmatg.Text = "";
83 txttentg.Text = "";
84 txtmatg.ReadOnly = false;
85 txttentg.ReadOnly = false;
86 txtmatg.Focus();
87 setbutton(false);
88 k = 1;
89 }
90
91 private void cmdCapnhat_Click(object sender, EventArgs e)
92 {
93 if (dgv_DMTG.SelectedRows.Count == 0)
94 {
95 RadMessageBox.Show("\nBạn phải chọn dòng để cập nhật !\n", "Thông Báo", MessageBoxButtons.OK, RadMessageIcon.Error);
96 return;
97 }
98 else
99 {
100 txttentg.ReadOnly = false;
101 txttentg.Focus();
102 setbutton(false);
103 k = 2;
104 }
105 }
106
107 private void cmdluu_Click(object sender, EventArgs e)
108 {
109 DialogResult rs = RadMessageBox.Show("\nBạn thật sự muốn lưu thông tin này không ?\n", "Thông Báo", MessageBoxButtons.YesNo, RadMessageIcon.Question);
110 if (rs == DialogResult.Yes)
111 {
112 if (k == 1)
113 {
114 if (txtmatg.Text == "" || txttentg.Text == "")
115 {
116 RadMessageBox.Show(this, "\nBạn phải nhập đầy đủ thông tin vào !\n", "Thông báo", MessageBoxButtons.OK, RadMessageIcon.Error);
117 return;
118 }
119 else
120 { //thêm mẩu tin mới vào datagirdview
121 c.them("tbl_dmTonGiao", int.Parse(txtmatg.Text.Trim())
122 , txttentg.Text.Trim());
123 }
124 }
125 else if (k == 2)
126 {
127 if (txtmatg.Text == "" || txttentg.Text == "")
128 {
129 RadMessageBox.Show(this, "\nBạn phải nhập đầy đủ thông tin vào !\n", "Thông báo", MessageBoxButtons.OK, RadMessageIcon.Error);
130 return;
131 }
132 else
133 {
134 //cập nhật mẩu tin
135 c.sua("tbl_DMTonGiao", int.Parse(txtmatg.Text.Trim()),
136 txttentg.Text.Trim(), "MaTG", "tenTG");
137 }
138 }
139 }
140 //load lại dữ liệu
141 c.laydl("tbl_DMTonGiao");
142 txtmatg.ReadOnly = true;
143 txttentg.ReadOnly = true;
144 k = 0;
145 setbutton(true);
146 }
147 }
148 }
149